package engine.ui.equipStrenGthen 
{
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.View;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import newx.BaseObject;
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.NxClip;
	import newx.com.control.text.NxLabel;
	/**
	 * ...
	 * @author ...WangHaiBo 
	 * ...........www.woniu.com
	 */
	public class RockChangeLogic implements IEquipLogic 
	{
		private static var _self:RockChangeLogic;
		private var viewgroup_left_7:NxViewGroup;
		private var lab_stonename_7:NxLabel;
		private var lab_needmoney_7:NxLabel;
		private var btn_star_7:NxButton;
		
		private var _viewData:BaseObject;
		private var _model:ModelLocator;
		public function RockChangeLogic(val:MovieClip) 
		{
			_model	=	ModelLocator.getInstance();
			viewgroup_left_7	=	val.getChildByName("viewgroup_left_7") as NxViewGroup;
			lab_stonename_7	=	val.getChildByName("lab_stonename_7") as NxLabel;
			lab_needmoney_7	=	val.getChildByName("lab_needmoney_7") as NxLabel;
			btn_star_7	=	val.getChildByName("btn_star_7") as NxButton;
			addListent();
		}
		public static function getInstance(dis:MovieClip):RockChangeLogic
		{
			if (_self == null) 
			{
				_self	=	new RockChangeLogic(dis);
			}
			return _self;
		}
		/* INTERFACE engine.ui.equipStrenGthen.IEquipLogic */
		/**
		 * 添加装备
		 * @param	val
		 */
		public function addEquip(val:BaseObject):void 
		{
			var item:MovieClip	=	viewgroup_left_7.getItemByIndex(0);
			while (item.numChildren > 1)
			{
				item.removeChildAt(1);
			}
			_viewData				=	val;
			var equipClip:NxClip	=	new NxClip();
			equipClip.width			=	equipClip.height	=	40;
			equipClip.x				=	2;
			equipClip.y				=	2;
			val.HandleProperties("NowViewType",View.VIEWPORT_RANDOMSTONE)
			item["data"]			=	val;
			equipClip.source		=	"res/items/icon_" + val.GetProperties("Photo") + ".jpg";
			item.addChild(equipClip);
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_RANDOMSTONE_GOLDCOIN);
			var equipItem:Object	=	StaticIni.getIniObj(_viewData.GetProperties("ConfigID"));
			equipName	=	StaticIni.getSwfLangStr(equipItem["NameID"]);
			
			checkStarBtnEnabled();
		}
		/**
		 * 移除装逼
		 * @param	val
		 */
		public function removeEquip(val:BaseObject):void 
		{
			var item:MovieClip	=	viewgroup_left_7.getItemByIndex(0);
			while (item.numChildren > 1)
			{
				item.removeChildAt(1);
			}
			_viewData				=	null;
			item["data"]			=	null;
			checkStarBtnEnabled();
			equipName	= "";
		
		}
		/**
		 * 清除所有显示对象信息
		 */
		public function removeAll():void 
		{
			var item:MovieClip	=	viewgroup_left_7.getItemByIndex(0);
			while (item.numChildren > 1)
			{
				item.removeChildAt(1);
			}
			_viewData				=	null;
			item["data"]			=	null;
			btn_star_7.enabled		=	false;
			lab_needmoney_7.htmlText	=	"";
			lab_stonename_7.htmlText	=	"";
		}
		/**
		 * 服务器返回消息
		 * @param	e
		 */
		private function  needMagicCoin(e:CustomMsgEvent):void
		{
			needMoney	=	e.pList[0];
		}
		/**
		 * 所需要的钱
		 */
		private function set needMoney(val:int):void
		{
			var textStr:String		=	"";
			var haveMenoy:Number	=	_model.scene.Role.getGoldCoin();
			var moneyType:String	=	StaticIni.getSwfLangStr("CapitalType_0");
			textStr					=	haveMenoy < val? "<font color='#FF0000'>" + String(val) + "</font>" :"<font color='#00FF40'>" + String(val) + "</font>" 
			lab_needmoney_7.htmlText	=	StaticIni.getSwfLangStrVar("NewItemChangeUIStr_52", [textStr, moneyType]);
		}
		/**
		 * 设定装备名
		 */
		private function set equipName(val:String):void
		{
			lab_stonename_7.htmlText	=	val;
		}
		/**
		 * 按钮是否可用;
		 */
		private function checkStarBtnEnabled():void
		{
			if (_viewData == null) 
			{
				btn_star_7.enabled	=	false;
			}
			else
			{
				btn_star_7.enabled	=	true;
			}
		}
		/**
		 * 洗宝石
		 * @param	e
		 */
		private function clickHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_RANDOMSTONE_BEGIN);
		}
		/**
		 * 添加侦听
		 */
		private function addListent():void
		{
			btn_star_7.addEventListener(MouseEvent.CLICK, clickHandle)
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_RADNOMSTONE_NEED_GOLDCOIN), needMagicCoin);
		}
		/**
		 * 移除侦听
		 */
		private function removeListent():void
		{
			btn_star_7.removeEventListener(MouseEvent.CLICK, clickHandle)
		}
		
		
	}

}